<?php
	
	require_once("fta.201003310000/fta.php");
	fta_registerModules(
		array(
		"cms.201003310000/config/cmsConfig",//we will deprecate the old cms config soon..
		"site/components/MAIEvent",
		"site/components/MAIExhibition",
		"site/fta/config",
		"FTAWebPage/ftaDefaultWidgets",
		"FTAWebPage/FTAWebPage"
	));
        
	global $FTAWebPageDocumentType;
	$FTAWebPageDocumentType = 'docWebSnip';
	
	$yearForCalendar = extractNumberWithKeyFromArray('yearForCalendar',$_REQUEST,date("Y"));
	
	$exhibitionList = mai_getExhibitionDatesForCalendar();//$yearForCalendar);
	//echo "exhibition dates = <pre>"; print_r($exhibitionDates);echo "</pre>";
					   //array("09/02/2010-09/03/2010", "09/07/2010-09/11/2010", "09/12/2010-09/13/2010", "10/01/2010-10/05/2010", "10/06/2010-10/11/2010", "10/12/2010-10/18/2010");
                                           
	$eventList = mai_getEventDatesForCalendar();//$yearForCalendar);
	//echo "event dates = <pre>"; print_r($eventDates);echo "</pre>";
				  //array("09/04/2010-09/05/2010", "09/08/2010-09/09/2010", "09/21/2010-09/23/2010", "10/19/2010-10/22/2010");
        
	/* TO DO!
	1. pull exhibitions and events into one array to pass to javascript
	2. have content to put into the table cell in separate array that can be indexed from javascript loop.
	3. need to check for double ups and put multiple links into the html array
	*/
	
	//GENERATE BOTH ARRAY
	$bothDates = array();
	foreach ($exhibitionList as $key=>$value){
		if(isset($eventList[$key])){
			
			$bothDates[$key] = $value;
			$bothDates[$key] .= $eventList[$key];
			
			unset($exhibitionList[$key]);
			unset($eventList[$key]);
		}
	}
	
	$exhibitionDate = array();
	$exhibitionContent = array();
	foreach ($exhibitionList as $key=>$value){
		$exhibitionDate[] = $key;
		$exhibitionContent[] = $value;
	}
	
	$eventDate = array();
	$eventContent = array();
	foreach ($eventList as $key=>$value){
		$eventDate[] = $key;
		$eventContent[] = $value;
	}

	//echo "Both Combined = <pre>";print_r($bothDates);echo "</pre>";
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<meta name="Keywords" content="<?php echo $metadataKeywords; ?>" />
<meta name="Description" content="<?php echo $metadataDescription; ?>" />

<title>Events and Exhibition | Mairangi Arts Centre</title>

<?php include ("includes/external-files.php"); ?>

<? /* ?><link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.8.0r4/build/calendar/assets/skins/sam/calendar.css">
<?php  */?>
<?php // /* ?>
		<link rel="stylesheet" type="text/css" href="/css/calendar.css">
<?php // */ ?>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/yui/2.8.1/build/yahoo-dom-event/yahoo-dom-event.js"></script> 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/yui/2.8.1/build/calendar/calendar-min.js"></script> 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/yui/2.8.1/build/datasource/datasource-min.js"></script> 

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"></script>




<link rel="stylesheet" type="text/css" href="/css/calendarGroup.css">
    
    
<link rel="stylesheet" type="text/css" href="/css/tipTip.css">
<script src="/js/jquery.tipTip.js"></script>


    
    
    
<?php include ("includes/analytics.php"); ?>   
</head>

<body id="events-calendar" class="yui-skin-sam">



<?php include ("includes/head.php"); ?>





<div id="container">


	<div id="content">
    	
        <h1>Events &amp; Exhibitions Calendar</h1>

         <img src="/images/calendar-key.gif" id="calendarKey">

            <div id="content-blocks">
        	                    

					<table border="0" cellspacing="0" cellpadding="0">
						<thead>
							<tr>
								<th>
									<div class="year-select">
										<div class="year-select-ctrl">
											<form id="previous" action="/Events-Calendar/" method="POST">
											<input type="hidden" name="yearForCalendar" value="<?php echo ($yearForCalendar -1); ?>" />
											<input type="submit" value="Previous Year" id="lastYear" />
											</form>
<?php /* <a id="lastYear" href="#" class="prev" title="Previous Year">Previous Year</a> */ ?> <h2 id="currentYear"><?= $yearForCalendar ?></h2> <?php /* <a id="nextYear"  href="#" class="next" title="Next Year">Next Year</a> */ ?>
											<form id="next" action="/Events-Calendar/" method="POST">
											<input type="hidden" name="yearForCalendar" value="<?php echo ($yearForCalendar +1); ?>" />
											<input type="submit" value="Next Year" id="nextYear" />
											</form>
										</div>
									</div>
								</th>
							</tr>
						</thead>
					</table>




				<div id="calGroup-container1"></div>
                  
                    
            </div><!-- Content-block ends -->

		</div><!-- Content-blocks ends -->
        
        
        
    
    
    



    </div><!-- Content ends -->








    
</div><!-- Container ends -->





<?php include ("includes/foot.php"); ?>


<script>

	var calGroup = new YAHOO.widget.CalendarGroup("calGroup","calGroup-container1",{PAGES:12, pagedate: "01/<?= $yearForCalendar ?>"});

	<?php /* foreach ($exhibitionList as $key=>$value){ ?>
	
		var allBookingsForRoom = [<?= json_encode($key); ?>];
	
		
		for (var i=0, c=allBookingsForRoom.length; i < c; i++){
			calGroup.addRenderer(allBookingsForRoom[i], function(workingDate, cell) {
			    cell.innerHTML = '';
			    var a = document.createElement('a');
			    a.href="/Exhibitions/Calendar/" + YAHOO.util.Date.format(workingDate,{format: '%F'}) + "/";
				a.className = "calendar-exhibition";
				a.title = "<?php echo $value; ?>";
			    a.innerHTML = 'Exhibition';
			    cell.appendChild(a);
			    YAHOO.util.Dom.addClass(cell, "exhibition");
		    	return YAHOO.widget.Calendar.STOP_RENDER; 
		    });
		}
	
	<?php }*/ ?>
	
	
		var allBookingsForRoom = <?= json_encode($exhibitionDate); ?>;
		var allBookingsForRoomContent = <?= "[\"" . implode("\", \"", $exhibitionContent) . "\"]"; ?>
		
		for (var i=0, c=allBookingsForRoom.length; i < c; i++){
			calGroup.addRenderer(allBookingsForRoom[i], function(workingDate, cell) {
			    cell.innerHTML = '';
			    var a = document.createElement('a');
			    a.href="/Exhibitions/Calendar/" + YAHOO.util.Date.format(workingDate,{format: '%F'}) + "/";
				a.className = "calendar-exhibition";
				a.title = "<div class='tooltip-exhibition'>" + allBookingsForRoomContent[i] + "</div>"; //"<?php //echo $value; ?>";
			    a.innerHTML = 'Exhibition';
			    cell.appendChild(a);
			    YAHOO.util.Dom.addClass(cell, "exhibition");
		    	return YAHOO.widget.Calendar.STOP_RENDER; 
		    });
		}
		
		<?php /* ?>
		var onholdForRoom = <?= json_encode($eventDate); ?>;
		var onholdForRoomContent = <?= "[\"" . implode("\", \"", $eventContent) . "\"]"; ?>
	
		for (var i=0, c=onholdForRoom.length; i < c; i++){
			calGroup.addRenderer(onholdForRoom[i], function(workingDate, cell) {
			    cell.innerHTML = '';
			    var a = document.createElement('a');
			    a.href="/Events/";
			    a.className = "calendar-both";
			    a.title = onholdForRoomContent[i];
				a.innerHTML = 'Event';
				cell.appendChild(a);
			    YAHOO.util.Dom.addClass(cell, "both"); 
		    	return YAHOO.widget.Calendar.STOP_RENDER; 
		    });
	
	<?php */ ?>
	<?php  foreach ($eventList as $key=>$value){ ?>
		var onholdForRoom = [<?= json_encode($key); ?>];
	
		for (var i=0, c=onholdForRoom.length; i < c; i++){
			calGroup.addRenderer(onholdForRoom[i], function(workingDate, cell) {
			    cell.innerHTML = '';
			    var a = document.createElement('a');
			    a.href="/Events/";
			    a.className = "calendar-event";
			    a.title = "<div class='tooltip-event'><?php echo $value; ?></div>";
				a.innerHTML = 'Event';
				cell.appendChild(a);
			    YAHOO.util.Dom.addClass(cell, "event"); 
		    	return YAHOO.widget.Calendar.STOP_RENDER; 
		    });
		}		
	<?php }  ?>
	
	<?php foreach ($bothDates as $key=>$value){ ?>
		var bothTypes = [<?= json_encode($key); ?>];
	
		for (var i=0, c=bothTypes.length; i < c; i++){
			calGroup.addRenderer(bothTypes[i], function(workingDate, cell) {
			    cell.innerHTML = '';
			    var a = document.createElement('a');
			    a.href="/Events/";
			    a.className = "calendar-both";
			    a.title = "<div class='tooltip-both'><?php echo $value; ?></div>";
				a.innerHTML = 'Event';
				cell.appendChild(a);
			    YAHOO.util.Dom.addClass(cell, "both"); 
		    	return YAHOO.widget.Calendar.STOP_RENDER; 
		    });
		}	
	<?php } ?>
	
	
	
	
	calGroup.render();
	
	YAHOO.util.Event.addListener('lastYear', 'click', function (e,el){
		el.previousYear();
		document.getElementById('currentYear').innerHTML = (new Date(el.pages[0].cfg.getProperty(YAHOO.widget.Calendar.DEFAULT_CONFIG.PAGEDATE.key))).getFullYear() ;	
	},calGroup);
	
	YAHOO.util.Event.addListener('nextYear', 'click', function (e,el){
		el.nextYear();
		document.getElementById('currentYear').innerHTML = (new Date(el.pages[0].cfg.getProperty(YAHOO.widget.Calendar.DEFAULT_CONFIG.PAGEDATE.key))).getFullYear() ;		
	},calGroup);	
</script>
		

<script type="text/javascript">
jQuery.noConflict();
var $j = jQuery;


	$j('.calendar-event, .calendar-exhibition, .calendar-both').tipTip({maxWidth: "400px", delay: 100, keepAlive: true});

</script>

</body>

</html>
